<?php

/**
 * @Author:             wuchenge
 * @Date:               2025-03-12 11:58:55
 * @Last Modified by:   wuchenge
 */
namespace App\Models;

use App\Models\Model;

class UserRecord extends Model
{

    /**
     * @var array
     */
    protected $fillable = ['user_id', 'admin_id', 'money'];

    /**
     * @var array
     */
    protected $guarded = ['created_at', 'updated_at'];

    /**
     * @var string
     */
    protected $table = 'user_record';

    /**
     * @return mixed
     */
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    /**
     * @return mixed
     */
    public function admin()
    {
        return $this->belongsTo(Admin::class, 'admin_id', 'id');
    }

    /**
     * @param $id
     * @param $money
     * @param $admin_id
     */
    public static function store($id, $money, $admin_id)
    {
        $data = [
            'money'    => $money,
            'user_id'  => $id,
            'admin_id' => $admin_id,
        ];

        $res = self::create($data);
        if (!$res) {
            return false;
        }

        return $res;
    }
}
